<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">浙江日报——报卡生成</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    卡片信息
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-6">
                            <form role="form" method="post" action="{:U('User/ZJDailyCard/update')}">
                                <input type="hidden" name="id" value="{$card['id']}" >
                                <div class="form-group">
                                    <label>卡号</label>
                                    <input type="text" class="form-control" value="{$card['cardnumber']}" name="cardnumber" disabled>
                                </div>
                                <div class="form-group">
                                    <label>卡密</label>
                                    <input type="text" class="form-control" value="{$card['password']}" name="password" disabled>
                                </div>

                                <div class="form-group">
                                    <label>发行年份</label>
                                    <select class="form-control" name="distribution_year" disabled>
                                        <option value="{$card['distribution_year']}">{$card['distributionyear']}</option>
                                    </select>
                                </div>
                                <if condition="$card['status'] gt 0">
                                <div class="form-group">
                                    <label>激活时间</label>
                                    <input type="text" class="form-control" value="{$card['signtime']}" name="signtime" disabled>
                                </div>
                                <div class="form-group">
                                    <label>激活用户</label>
                                    <input type="text" class="form-control" name="username" value="{$addr['username']}" >
                                </div>
                                <div class="form-group">
                                    <label>联系电话</label>
                                    <input type="text" class="form-control" value="{$addr['telephone']}" name="telephone" >
                                </div>
                                <div class="form-group">
                                    <label>职业</label>
                                    <!--<input type="text" class="form-control" name="metier" value="{$addr['metier']}" > -->
                                    <select class="form-control" name="metier">
                                        <option value="政府机关/事业单位" <if condition="$addr['metier'] eq '政府机关/事业单位'">selected</if>>政府机关/事业单位</option>
                                        <option value="国有企业" <if condition="$addr['metier'] eq '国有企业'">selected</if>>国有企业</option>
                                        <option value="民营企业" <if condition="$addr['metier'] eq '民营企业'">selected</if>>民营企业</option>
                                        <option value="离退休" <if condition="$addr['metier'] eq '离退休'">selected</if>>离退休</option>
                                        <option value="学生" <if condition="$addr['metier'] eq '学生'">selected</if>>学生</option>
                                        <option value="其他" <if condition="$addr['metier'] eq '其他'">selected</if>>其他</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>省</label>
                                    <select class="form-control province" name="province" id="province" data-default="{$addr['province']}" >
                                        <option value="{$addr['province']}" >请选择</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>市</label>
                                    <select class="form-control city" name="city" id="city" data-default="{$addr['city']}" >
                                        <option value="{$addr['city']}" >请选择</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>区</label>
                                    <select class="form-control region" name="county" id="region" data-default="{$addr['county']}" >
                                        <option value="{$addr['county']}" >请选择</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>详细地址</label>
                                    <textarea type="text" class="form-control" name="address" rows="3" >{$addr['address']}</textarea>
                                </div>
                                </if>

                                <div class="form-group">
                                    <label>有效日期</label>
                                    <if condition="strtotime($card['begintime'])">
                                    <input class="form-control form_datetime margin-vertical-default" data-date-format="yyyy-mm-dd hh:ii:ss" name="begin_date"  placeholder="起始日期" value="{$card['begintime']}" disabled>
                                    <else />
                                    <input class="form-control form_datetime margin-vertical-default" data-date-format="yyyy-mm-dd hh:ii:ss" name="begin_date"  placeholder="起始日期" value="" disabled>
                                    </if>
                                    <if condition="strtotime($card['endtime']) gt 0">
                                    <input class="form-control form_datetime margin-vertical-default" data-date-format="yyyy-mm-dd hh:ii:ss" name="end_date" placeholder="失效日期" value="{$card['endtime']}" disabled>
                                    <else />
                                    <input class="form-control form_datetime margin-vertical-default" data-date-format="yyyy-mm-dd hh:ii:ss" name="end_date" placeholder="失效日期" value="" disabled>
                                    </if>
                                </div>
                                <button type="submit" class="btn btn-default">提交</button>
                            </form>
                        </div>
                        <!-- /.col-lg-6 (nested) -->
                    </div>
                    <!-- /.row (nested) -->
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>
<!-- /#page-wrapper -->
<script src="/Public/js/bootstrap/bootstrap.min.js" type="text/javascript"></script>
<link href="/Public/css/bootstrap/bootstrap-datetimepicker.css" rel="stylesheet">
<script src="/Public/js/bootstrap/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="/Public/js/bootstrap/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<script type="text/javascript" src="/Public/zjdailyCard/js/offline.china.js"></script>
<script type="text/javascript">
$( ".form_datetime" ).datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    forceParse: 0,
    showMeridian: 0
});
</script>
<script type="text/javascript">
var miniCity = ( function(){
    var _provience = undefined;
    var _city = undefined;
    var _region = undefined;

    var _changeProvience = function( code ){
        !code && ( code = $(this).val() );
        var options = undefined;
        if( code > 0 ){
            options = "<option value=0>请选择</option>";
            for( var i in offline.china.cities[code] ){
                options += "<option value="+i+">"+ offline.china.cities[code][i] + "</option>";
            }
            _city.html("");
            _city.append( $(options) ).trigger( "change" );
        };
        /*(code > 0) && $.get( '/?m=user&c=miniCity&a=check', { code: code }, function(result){
            options = "<option value=0>请选择</option>";
            for( var i in result.sons ){
                options += "<option value="+result.sons[i].id+">"+result.sons[i].regionname + "</option>";
            }
            //_provience.html( "" );
            _city.html("");
            //_provience.append( $( "<option value="+result.parent.id+">" + result.parent.regionname + "</option>") );
            _city.append( $(options) ).trigger( "change" );
        });*/
        (code == 0) && _city.html( "<option value=0>请选择</option>" ).trigger("change");
    };
    var _changeCity = function( code, region ){
        !code && ( code = $(this).val() );
        if( code > 0 ){
            options = "<option value=0>请选择</option>";
            for( var i in offline.china.counties[code] ){
                options += "<option value="+i+">"+offline.china.counties[code][i] + "</option>";
            }
            _region.html("");
            _city.find( "option[value=" + code + "]" ).attr( 'selected', true );
            _region.append( $(options) );
            region && _region.find( "option[value=" + region + "]" ).attr( "selected", true ).trigger( "change" );
            region == undefined && _region.trigger( "change" ); 
        }
        /*( code > 0 ) && $.get( '/?m=user&c=miniCity&a=check', { code: code }, function(result){
            options = "<option value=0>请选择</option>";
            for( var i in result.sons ){
                options += "<option value="+result.sons[i].id+">"+result.sons[i].regionname + "</option>";
            }
            _region.html("");
            _city.find( "option[value=" + code + "]" ).attr( 'selected', true );
            //_city.find( "option[value=" + code + "]" ).prop( 'selected', true );
            _region.append( $(options) );
            region && _region.find( "option[value=" + region + "]" ).attr( "selected", true ).trigger( "change" );
            region == undefined && _region.trigger( "change" ); 
        });*/
        ( code == 0 ) &&  _region.html("<option value=0>请选择</option>").trigger( "change" );
    };
    var changeRegion = function( code ){
    };

    var _initProvience = function( code, selected ){
        /*$.post( '/?m=user&c=miniCity&a=checks', {codes: code}, function( result ){
             var options = "<option value=0>请选择</option>";
             for( var i in result ){
                options += "<option value=" + result[i].id + ">" + result[i].regionname + "</option>"
             }
             _provience.html( "" );
             _provience.html( options );
             _provience.find( "option[value="+selected+"]" ).attr( "selected", true );
        });*/
        var options = "<option value=0>请选择</option>";
        for( var i in code ){
            options += "<option value=" + code[i] + ">" + offline.china.provinces[code[i]] + "</option>"
        }
        _provience.html( "" );
        _provience.html( options );
        _provience.find( "option[value="+selected+"]" ).attr( "selected", true );

    }
    return {
        init: function( s_provience, s_city, s_region, provience, city, region ){
            _provience = $( s_provience );
            _city = $( s_city );
            _region = $( s_region );
            _initProvience( [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], provience );
            //_initProvience( [ 31 ], provience );
            provience && _changeProvience( provience );
            city && _changeCity( city, region );

            _provience.bind( "change", function(){
                    _changeProvience( $(this).val() );
            });                
            _city.bind( "change", function(){
                _changeCity( $(this).val() );
            });
        },
        //changeCity: _changeCity
    }
})();
miniCity.init( ".province", ".city", ".region", $("#province").data("default"), $("#city").data("default"), $("#region").data("default") );
</script>
